//
//  ShareView.swift
//  ptbuy
//
//  Created by MyMac on 2024/12/2.
//
import SwiftUI
import UIKit
class ShareView {
 
    
    public static func shareContent(content:String,url:String) {
                let urlToShare = URL(string: url)!
        
            // 创建 UIActivityViewController
            let activityViewController = UIActivityViewController(activityItems: [content, urlToShare], applicationActivities: nil)
            
            // iPad 需要特别指定 Popover
            if let popoverController = activityViewController.popoverPresentationController {
                
                if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
                   
                    popoverController.sourceView = windowScene.windows.first?.rootViewController?.view
                }
                
               
                popoverController.sourceRect = CGRect(x: 0, y: 0, width: 1, height: 1)
            }
            
            // 获取当前的视图控制器
            if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
               
                if let rootViewController  = windowScene.windows.first?.rootViewController{
                    rootViewController.present(activityViewController, animated: true, completion: nil)
                }
            }
        
        
    }
}
